package com.whopxx.controller;


import com.whopxx.domain.vo.ResultVO;
import com.whopxx.service.FileUploadService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileUploadService fileUploadService;

    @PostMapping(value = "/upload",consumes = "multipart/form-data")
    public ResultVO<Long> upLoad(@RequestPart MultipartFile file) {
        Long fileId = fileUploadService.upload(file);
        return ResultVO.success(fileId);
    }

    @GetMapping("/download/{fileId}")
    public void download(@PathVariable Long fileId, HttpServletResponse response) {
        fileUploadService.download(fileId, response);
    }

}
